<?php
/**                                          
 * 公用类             
 * @author M2
 * @version 1.0
 * create Date 2013-04-27
 */
class CommonAction extends Action {
    protected $site;
	protected $user;
	protected $mid;
	protected $uid;
	
	function _initialize() {
		// 站点配置信息
		$this->siteOpt();
                
		// 用户登录信息
		if(intval($_SESSION['mid']) > 0){
			$this->userInfo();
		}else{
			//$urluid=$this->urluserid();
			$urluid="";
			if(!empty($urluid)){
				$_SESSION['mid']=$urluid;
				$this->userInfo();
			}else{
				$topNav = model("Nav") ->getTopNav("1");
				global $yl;
				$yl['topNav'] = $topNav;
			}
 		}
 		 	if($_SESSION['article_id'] > 0)
 	 		$this->article_id =$_SESSION['article_id'];
		// 关注
		$data ['followTopic'] = model('Follow')->getTopicList ( $this->mid );
		$this->assign ( $data );
	}
	
	
	
	function urluserid(){
	// 		$ch = curl_init();
// 		$str =URL('comments/Comments/getuserid');
// 		curl_setopt($ch, CURLOPT_URL, $str);
// 		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
// 		$output = curl_exec($ch);
// 		curl_close($ch);
		//return  $output;
	}
	
	
	/**
     * 设置页面标题
     * @param string $title 页面标题
     * @param string $keywords 关键字
     * @param strign $description 网站内容描述
     */
    public function setTitle($title='',$keywords='',$description=''){
    	global $yl;
    	if($title)
            $yl['site']['page_title'] = $title;
        if($keywords)
            $yl['site']['site_header_keywords'] = $keywords;
        if($description)
            $yl['site']['site_header_description'] = $description;
	}

	/**
	 * 获取用户信息	
	 */
	public function userInfo() {
		$this->mid = intval($_SESSION['mid']);
		$this->uid = intval($_REQUEST['uid']);
		if ($this->uid == 0)
			$this->uid = $this->mid;
		// 获取userInfo数据
		if ($this->mid > 0 && (empty ($_SESSION['userInfo']) || !$_SESSION['userInfo']['is_init'] || !$_SESSION['userInfo']['is_active'])) {
			$_SESSION['userInfo'] = model('User')->getUserByIdentifier($this->mid);
		} else {
			if (empty ($_SESSION['userInfo'])) {
				return true;
			}
			model('User')->setUserObjectCache(array (
				$_SESSION['userInfo']
			));
		}

		//缓存登录用户个人资料
		$userInfo = model('User')->getUserInfoCache($this->mid);
		$this->assign('userInfoCache', $userInfo);
		$apps = model('UserApp');
		$list = $apps->getInstallApps($this->mid);
		$this->assign('cc',$list);
		// 赋值当前用户
		$this->user = $_SESSION['userInfo'];
		
		$topNav = model("Nav") ->getTopNav(); 
		global $yl;
		if(session('?administrator'))
			$yl['isSystemAdmin'] = true;
		$yl['topNav'] = $topNav;
		$yl['app'] = $list;
		$yl['user'] = $this->user;
		$this->assign('mid', $this->mid);
		$this->assign('uid', $this->uid);
		$this->assign('user', $this->user);
	}

	/**
	 * 获取站点信息	
	 */
	public function siteOpt() {
		$siteopt = model('Data')->lget('siteopt');
		$siteseo = model('Data')->lget('siteseo');
		$siteweibo = model('Data')->lget('weibo');
		$siteannouncement = model('Data')->lget('announcement');
		global $yl;
		$yl['site'] = array_merge(array_merge($siteopt,$siteseo),array_merge($siteweibo,$siteannouncement));
		//微博、评论字数限制，默认150
        $yl['site']['length'] = $yl['site']['length'] > 0 ? $yl['site']['length'] : 150;
		$this->site = $yl['site'];
	}
	
}
?>